#include<bits/stdc++.h>
#define ll long long
using namespace std;
vector<pair<ll,ll> > edge[200005];
ll ans=0,n,q,a,b,c;
int dfs(int u,int fa,int l,int r){
	int cnt=0,x;
	if(l<=u&&u<=r)cnt=1;
	for(auto i:edge[u]){
		if(i.first!=fa){
			cnt+=(x=dfs(i.first,u,l,r));
			if(x==r-l+1)ans+=i.second; 
		}
	}
	return cnt;
}
int main(){
	ios::sync_with_stdio(0);cin.tie(0),cout.tie(0); 
  	freopen("memory.in","r",stdin);
  	freopen("memory2.out","w",stdout);
	cin>>n>>q;
	for(int i=1;i<n;i++){
		cin>>a>>b>>c;
		edge[a].emplace_back(b,c);
		edge[b].emplace_back(a,c);
	}
	while(q--){
		cin>>a>>b>>c;
//		a^=ans;b^=ans;c^=ans;
		ans=0;
		dfs(a,0,b,c);
		cout<<ans<<'\n';
	}
}
